package com.zoffy.zoffyapi.exception;

import com.zoffy.zoffyapi.commen.BaseResponse;
import com.zoffy.zoffyapi.commen.ResultUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    @ExceptionHandler(BusinessException.class)
    public BaseResponse<?> businessExceptionHandler(BusinessException e) {
        return ResultUtils.error(e.getCode(), e.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public BaseResponse<?> RuntimeExceptionHandler(Exception e) {
        log.error("ErrorMessage:"+e);
        e.printStackTrace();
        return ResultUtils.error(ErrorCode.SYSTEM_ERROR);
    }
}
